﻿namespace Yzk_Practice;

class Program
{
    static  void Main(string[] args)
    {
        /*
        string path = @"E:\LiufengProjects\RiderProjects\PracticeFile\htmlString.html";
        if (await GetHtmlStringAsync("https://www.baidu.com", path))
        {
            Console.WriteLine("get html string success!");
            return;
        }

        Console.WriteLine("get html string failed!");
        */
        string path = @"E:\LiufengProjects\RiderProjects\PracticeFile\htmlString.html";
        var result = File.ReadAllTextAsync(path).Result;
        Console.WriteLine(result);
    }

    static async Task<bool> GetHtmlStringAsync(string url, string filePath)
    {
        using HttpClient hc = new HttpClient();
        var result = await hc.GetStringAsync(url);
        if (result.Length > 0)
        {
            await File.WriteAllTextAsync(filePath, result);
            return true;
        }

        return false;
    }
} 